package com.ruifu.pls.repository;

import com.ruifu.pls.entity.DocAsnHeader;
import com.ruifu.pls.entity.DocOrderHeader;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import javax.transaction.Transactional;

/**
 * ********************************************************
 * * @desc  ：
 * * @author  ${user}
 * * @date    ${date}
 * * @version v1.0
 * * ${tags}
 * *******************************************************
 */

public interface StatusUpdateRepository  extends PagingAndSortingRepository<DocAsnHeader, String>,JpaSpecificationExecutor<DocAsnHeader> {
    @Query
            (value = "    select * from ( select * from doc_asn_header asn  where asn.h_edi_08  is null  and (USERDEFINE5 is null or USERDEFINE5!='11') and (edisendflag = 'N' or edisendflag = 'S') AND (warehouseid='NSLDS' or warehouseid='JD_TEST') and asnreference1 is not null and customerid is not null order by asn.asncreationtime desc ) where ROWNUM = 1 ",nativeQuery = true)
    public  DocAsnHeader findByAsnHeader();
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE  doc_asn_header SET USERDEFINE5=?2 WHERE   asnno =?1 ",nativeQuery = true)
    public  void updateStatus(String asnno, String status);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE  doc_order_header SET USERDEFINE5=?2 WHERE   orderno =?1 ",nativeQuery = true)
    public  void updateStatusOrder(String orderno, String status);

    @Query(value="SELECT * from (select * from doc_order_header where edisendflag = 'N' AND warehouseid='JD_TEST'   order by addtime desc) where ROWNUM = 1 ",nativeQuery=true)
    public DocOrderHeader findByOrderHeader();


    @Query(value="SELECT * from (select * from doc_order_header where edisendflag = 'N' AND warehouseid='JD_TEST' and ordertype='XSCK' AND SOSTATUS = 80 order by addtime desc) where ROWNUM = 1 ",nativeQuery=true)
    public DocOrderHeader findByDocOrderHeader();


   /* @Query(value="SELECT * from (select * from doc_order_header where edisendflag = 'N' AND warehouseid='JD_TEST'  AND SOSTATUS = 99 order by addtime desc) where ROWNUM = 1 ",nativeQuery=true)
    public DocOrderHeader findByDocOrderHeader2();*/


}
